<template>
  <ex-dialog
    width="50%"
    class="ex-diolog"
    title="详情"
    :visible="visible"
    @closeDialog="handleClose"
  >
    <!-- 企业 -->
    <grid-layout>
      <!-- <grid-item label="注册信息">填写信息</grid-item> -->
      <grid-item label="注册类型" v-if="data.merchantType === '1'">企业</grid-item>
      <grid-item label="注册类型" v-if="data.merchantType === '2'">个人</grid-item>
      <grid-item label="商户账号名称">{{ data.merchantName }}</grid-item>
      <grid-item label="营业执照注册号">{{ data.businessLicenseNumber }}</grid-item>
      <grid-item label="注册地址">{{ data.address }}</grid-item>
      <grid-item label="法人姓名">{{ data.name }}</grid-item>
      <grid-item label="联系电话">{{ data.phone }}</grid-item>
      <grid-item label="店铺名称">{{ data.shopName }}</grid-item>
      <grid-item label="店铺类型">{{ data.shopTypeName }}</grid-item>
      <grid-item label="上传企业营业执照"><ex-image
        class="img"
        v-if="data.businessLicenseImg"
        :src="data.businessLicenseImg"
        :preview-src-list="[data.businessLicenseImg]"
      />
      </grid-item>
      <grid-item label="审核状态">{{ data.statusDict}}</grid-item>
    </grid-layout>

    <!-- 个人 -->
    <!-- <grid-layout v-else-if="data.merchantType === '2'" class="grid-layout">
      <grid-item label="注册信息">填写信息</grid-item>
      <grid-item label="手机号">{{ data.phone }}</grid-item>
      <grid-item label="注册类型">个人</grid-item>
      <grid-item label="注册邮箱">{{ data.email || '-' }}</grid-item>
      <grid-item label="姓名">{{ data.name }}</grid-item>
      <grid-item label="身份证">{{ data.idCard }}</grid-item>
      <grid-item label="身份证图片">
        <ex-image
          class="img"
          :src="data.idCardFront"
          :preview-src-list="[data.idCardFront]"
        />
        <ex-image
          class="img"
          :src="data.idCardReverse"
          :preview-src-list="[data.idCardReverse]"
        />
      </grid-item>
      <grid-item label="个体商家能力">{{ data.merchantAbility }}</grid-item>
      <grid-item label="邀请码">{{ data.invitationCode }}</grid-item>
      <grid-item label="申请状态">{{ data.statusDict }}</grid-item>
    </grid-layout> -->

    <template v-if="data.status == '3'" slot="footer">
      <el-button type="danger" @click="rejectClick">拒绝</el-button>
      <el-button type="primary" @click="agreeClick">同意</el-button>
    </template>
  </ex-dialog>
</template>
<script>
// api
import {
  getDetail,
  approved,
  reject
} from '@/api/regitserVerify'

export default {
  props: {
    visible: Boolean,
    id: String,
 
  },
  data() {
    return {
      types: {
        '1': '企业',
        '2': '个人'
      },
      status: {
        '1': '正常',
        '2': '冻结'
      },
      img_url: this.$IMG_URL,
      data: {}
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    getDetail() {
      getDetail(this.id).then(res => {
        console.log('获取详情', res)
        const { result } = res
        result.merchantTypeText = this.$getStatusText('merchant_type', result.merchantType)
        result.statusText = this.$getStatusText('account_status', result.status)
        result.applyStatusText = this.$getStatusText('register_verify_status', result.applyStatus)

        this.data = result
      })
    },
    handleClose() {
      this.$emit('update:visible', false)
    },

    handleSuccess(msg) {
      if (msg === '已拒绝') {
        var type = 'error'
      } else {
        var type = 'success'
      }
      this.$message({
        message: msg,
        type: type,
        duration: 1500,
        onClose: () => {
          this.handleClose()
          this.$emit('success')
        }
      })
    },

    rejectClick() {
      this.$confirm('是否拒绝?', '提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      }).then(() => {
        console.log('hgahah')
        reject(this.id).then(res => {
          this.$message({
            message: '已拒绝【'+this.data.merchantName+'】入驻申请',
            type: 'error',
            duration: 1500,
          })
          this.$emit('success')
        })
      }).catch()
    },

    agreeClick() {
      this.$confirm('是否同意?', '提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      }).then(() => {
        approved(this.id).then(res => {
          this.$message({
            message: '已同意【'+this.data.merchantName+'】入住申请',
            type: 'success',
            duration: 1500,
          })
          this.$emit('success')
        })
      }).catch()
    }
  }
}
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
  }
  .grid-layout {
    width: 560px;
    margin: 0 auto;
  }
  .img {
    display: block;
    width: 100px;
    height: auto;
  }
}
</style>
